#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
	const int LENGTH = 1000;
	char s[LENGTH];
	memset(s, 0, LENGTH);
	cin>>s;
	while (s[0] != '0' || strlen(s) != 1) {
		int n = 0;
		for (int i = 0; i < (int)strlen(s); i++) {
			n += (s[i] - '0');
		}
		int digits1;
		int digitalRoot = 0;
		while (n > 0) {
			digits1 = n % 10;
			digitalRoot += digits1;
			if (digitalRoot >= 10) 
			{
				digitalRoot = (digitalRoot / 10) + (digitalRoot % 10);
			}
			n /= 10;
		}
		cout<<digitalRoot<<endl;

		cin>>s;
	}
	return 0;
}